package com.lemon.components.ant.util.freemarker;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.lemon.components.ant.project.beans.ColumnInfo;
import com.lemon.components.ant.project.beans.TableInfo;
import com.lemon.components.ant.util.ConfigUtil;
import com.lemon.components.docs.mysql.MysqlLocalTool;
import com.lemon.ui.codemaker.component.RecentlyFile;

import freemarker.template.SimpleScalar;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;

public class FetchJdbcComment implements TemplateMethodModelEx{

	@Override
	public Object exec(List args) throws TemplateModelException {
		String tableName = ((SimpleScalar)args.get(0)).getAsString();
		String columnName = ((SimpleScalar)args.get(1)).getAsString();
		if(StringUtils.isBlank(tableName)) {
			return "非原生表属性，请补注释";
		} else {
			List<TableInfo> tablesinfo = MysqlLocalTool.getTableInfo(ConfigUtil.getInstance(RecentlyFile.configFilePath).getProjectInfoNoTable());
			ColumnInfo columnInfo = MysqlLocalTool.getColumnInfo(tablesinfo, tableName, columnName);
			if(columnInfo == null) {
				return "<未知属性，请手动补充注释>";
			} else {
				return columnInfo.getColumnRemark();
			}
		}
	}

}
